﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentNHibernate.Mapping;
using Entities;

namespace Mapping
{
    public class StudyPlanItemMap : ClassMap<StudyPlanItem>
    {
        public StudyPlanItemMap()
        {
            Id(x => x.Id)
                .GeneratedBy.Identity();
            References(x => x.Discipline)
                .Column("DisciplineId")
                .ForeignKey()
                .Nullable()
                .Cascade.SaveUpdate();
            References(x => x.Department)
                .Column("DepartmentId")
                .ForeignKey()
                .Nullable()
                .Cascade.SaveUpdate();
            References(x => x.Direction)
                .Column("DirectionId")
                .ForeignKey()
                .Nullable()
                .Cascade.SaveUpdate();
            Map(x => x.HoursLaboratory);
            Map(x => x.HoursLecture)
                .Not.Nullable();
            Map(x => x.HoursPractice).Not.Nullable();
            Map(x => x.HoursSRS).Not.Nullable();
            Map(x => x.Semestr).Not.Nullable();
            Map(x => x.TypeSRS).Not.Nullable();
            Map(x => x.ControlType).Not.Nullable();
            HasManyToMany(x => x.Allocations)
                .ParentKeyColumn("StudyPlanItemId")
                .ChildKeyColumn("AllocationId")
                .Cascade.All()
                .Inverse()
                .Table("SPItemAllocation");
        }
    }
}
